//
// Created by 刘进伟 on 2018/5/19.
//

#ifndef COMPILER_FILERW_H
#define COMPILER_FILERW_H

#include <stdio.h>
#include <iostream>
#include <map>
#include <list>
#include <string.h>
#include <string>
#include "Common.h"

#define BUFFERLENGTH 2048

class FileRW {
private:
    FILE * srcFile=NULL;
    char inputBuffer[BUFFERLENGTH];
    char memLastChar=-1;

    int bufferLength=0;
    int currentLex=0;

    int lineNumber=1;

    std::map<const char,CharType > CHAR_SET;
    std::map<std::string,LexType > WORD_SET;

    void readFile();
    char readChar();
    CharType findCharType(char & obj);
    bool isNumber(char * str);
public:
    FileRW(const char * fileName);
    ~FileRW();
    Char & getNextChar();
    void ungetNextChar();
    void setWordType(struct Token & token);
    static bool writeFile(std::list<Token> & tokens);
};


#endif //COMPILER_FILERW_H
